<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>home</title>
</head>
<body>
<img id = "light" src = "img/off.gif" >

<script>
    var light = document.getElementById("light");
    var flag = false;
    //表示灯是灭的
    light.onclick = function(){
        if(!flag)
        {
            flag = true;
            light.src = "img/on.gif";
        }
        else
        {
        flag=false;
            light.src = "img/off.gif";
        }
    }
</script>
</body>
</html>